package com.ccbooks.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

import cc.software.books.format.Plugin;
import cc.software.books.format.PluginChm;

import com.ccbooks.view.BookContentView;

import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class ContentUtilReturn implements Runnable{

	public String fileName;
	public String fontName;
	public int width;
	public String charSet;
	public int percent;
	public int lineNo;
	public int lineCount;

	
	public BooksEngine engine;
	BookContentView bcv;
	private TextView tv;
	public int what;	//决定是在哪一个textview显示；
	
	public ContentUtilReturn(BookContentView bcv,String fileName, String fontName, int width,
			String charSet,int portraint,BooksEngine engine) {
		super();
		this.bcv = bcv;
		this.fileName = fileName;
		this.fontName = fontName;
		this.width = width;
		this.charSet = charSet;
		this.engine = engine;
	}
	
	public void setLine(int lineNo,int lineCount){
		this.lineNo = lineNo;
		this.lineCount = lineCount;
	}
	
	public void firstThread(){	
		
		try {
			engine.engineInit(bcv, fontName, width, charSet);
			//此方法用于读行；
			//engine.parseFile();
			//content = engine.getPageContent(lineNo, lineCount);
			//此方法用来读取百分比
			engine.status = 1;
			engine.parseFileReturn(fileName, TextSizeUtil.getLineCount(TextSizeUtil.fontSize, bcv.portraint));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public void nextPage(){
		
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub
		bcv.turnable= false;
		firstThread();
		bcv.turnable = true;
		bcv.bcHandler.sendEmptyMessage(5);
	}
}
